package uy.edu.ort.arqsw.domino;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author SG0892177
 */
@Entity
@Table(name = "entradablog", catalog = "test", schema = "")

@NamedQueries({
    @NamedQuery(name = "EntradaBlog.findAll", query = "SELECT e FROM EntradaBlog e"),
    @NamedQuery(name = "EntradaBlog.findById", query = "SELECT e FROM EntradaBlog e WHERE e.id = :id"),
    @NamedQuery(name = "EntradaBlog.findByFecha", query = "SELECT e FROM EntradaBlog e WHERE e.fecha = :fecha"),
    @NamedQuery(name = "EntradaBlog.findByTitulo", query = "SELECT e FROM EntradaBlog e WHERE e.titulo = :titulo"),
    @NamedQuery(name = "EntradaBlog.findByAutor", query = "SELECT e FROM EntradaBlog e WHERE e.autor = :autor")})

public class EntradaBlog implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Temporal(TemporalType.DATE)
    private Date fecha;
    private String titulo;
    private String contenido;
    private String autor;

    @ManyToMany
    private List<Tag> tags;
        
    public EntradaBlog()
    {
        this.titulo = "";
        this.autor = null;
        this.contenido = "";
        this.tags = new ArrayList<Tag>();
    }
    
    
    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    
    
    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }
    
    public String getAutor() {
        return autor;
    }

    public void setAutor(String autor) {
        this.autor = autor;
    }

    public List<Tag> getTags() {
        return tags;
    }

    public void setTags(ArrayList<Tag> tags) {
        this.tags = tags;
    }
    
        public String getContenido() {
        return contenido;
    }

    public void setContenido(String contenido) {
        this.contenido = contenido;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

        
    public void agregarTag(Tag unTag){
        //tags.add(unTag);
        
      if (!getTags().contains(unTag)) {
          getTags().add(unTag);
      }
      if (!unTag.getEntradaBlogs().contains(this)) {
          unTag.getEntradaBlogs().add(this);
      }
        
        
    }
    
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EntradaBlog)) {
            return false;
        }
        EntradaBlog other = (EntradaBlog) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.EntradaBlog[ id=" + id + " ]";
    }
    
}
